﻿Imports System.Windows.Forms
Imports System.Data.SqlClient


Public Class FRMcsfupdate
    Private _section As Integer
    Private _csf As Integer
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Dim sQry As String = ""
        If TextBox1.Text.Trim > 0 Then
            'sQry = "Exec UpdateCSF @csfid=" & TextBox1.Text.Trim & ",@facid=" & Me.ComboBox3.SelectedValue
            sQry = "Update CSF Set Faculty_Id=@facid WHERE (csf_id = @csfid)"
            Dim cn As New SqlConnection
            cn.ConnectionString = My.Settings.eCollegeConnectionString
            Dim cmd1 As New SqlCommand(sQry, cn)

            cmd1.Parameters.Add("@facid", SqlDbType.Int)
            cmd1.Parameters("@facid").Value = Me.ComboBox3.SelectedValue

            cmd1.Parameters.Add("@csfid", SqlDbType.Int)
            cmd1.Parameters("@csfid").Value = TextBox1.Text.Trim

            cn.Open()
            ' MsgBox(sQry)
            'Dim cmd As New SqlCommand(sQry, cn)
            cmd1.ExecuteNonQuery()
            If cn.State = ConnectionState.Open Then cn.Close()
            cmd1.Dispose()
            cn.Close()
        Else
            'sQry = "INSERT INTO [CSF] ([Section_Id] ,[Subject_Code],[Faculty_Id],[IsRemoved],[Assign_Date] ,[SessionID])         VALUES (" & Me.ComboBox1.SelectedValue & " ,'" & Me.ComboBox2.SelectedValue & "' ," & Me.ComboBox3.SelectedValue & ",0 ,Current_timestamp  ,11 )"
            sQry = "INSERT INTO [CSF] ([Section_Id],[Subject_Id] ,[Subject_Code],[Faculty_Id],[IsRemoved],[LA],[TA],[PA]) VALUES (" & Me.ComboBox1.SelectedValue & " ,'" & Me.ComboBox2.SelectedValue & "' ,'" & Me.ComboBox2.Text.Trim & "' ," & Me.ComboBox3.SelectedValue & ",0," & Me.nLA.Value & " ," & Me.nTA.Value & " ," & Me.nPA.Value & ")"
            Dim cn As New SqlConnection
            cn.ConnectionString = My.Settings.eCollegeConnectionString
            cn.Open()
            ' MsgBox(sQry)
            Dim cmd As New SqlCommand(sQry, cn)
            cmd.ExecuteNonQuery()
            If cn.State = ConnectionState.Open Then cn.Close()
        End If
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()

    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub csfupdate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ECollegeDataSet.Teacher' table. You can move, or remove it, as needed.
        Me.TeacherTableAdapter.Fill(Me.ECollegeDataSet.Teacher)
        'TODO: This line of code loads data into the 'ECollegeDataSet.Subject' table. You can move, or remove it, as needed.
        Me.SubjectTableAdapter.Fill(Me.ECollegeDataSet.Subject)
        'TODO: This line of code loads data into the 'ECollegeDataSet.Section' table. You can move, or remove it, as needed.
        Me.SectionTableAdapter.Fill(Me.ECollegeDataSet.Section)
        'TODO: This line of code loads data into the 'ECollegeDataSet.Teacher' table. You can move, or remove it, as needed.
        Me.TeacherTableAdapter.Fill(Me.ECollegeDataSet.Teacher)
        'TODO: This line of code loads data into the 'ECollegeDataSet5.V_Faculty' table. You can move, or remove it, as needed.
        'Me.DisplayRectangle'_FacultyTableAdapter.Fill(Me.ECollegeDataSet.V_Faculty)
        'TODO: This line of code loads data into the 'ECollegeDataSet5.M_Subject' table. You can move, or remove it, as needed.
        'Me.M_SubjectTableAdapter.Fill(Me.ECollegeDataSet5.M_Subject)
        Me.ComboBox1.Enabled = False
        _section = _currentSection
        ' Me.ComboBox1.SelectedValue = _section
        _csf = _currentcsf
        Me.TextBox1.Text = _csf
        'Try
        '    Me.M_SectionTableAdapter.FillBy1(Me.ECollegeDataSet.M_Section, CType(_currentSession, Integer))
        'Catch ex As System.Exception
        '    System.Windows.Forms.MessageBox.Show(ex.Message)
        'End Try
        'Try
        '    'Me.M_SectionTableAdapter.FillBy3(Me.ECollegeDataSet.M_Section)
        '    MessageBox.Show("err:3")
        'Catch ex As System.Exception
        '    System.Windows.Forms.MessageBox.Show(ex.Message)
        'End Try
    End Sub


    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If Me.CheckBox1.Checked Then
            Me.ComboBox1.Enabled = True
            Me.TextBox1.Text = 0
        Else
            Me.ComboBox1.Enabled = False
            Me.TextBox1.Text = _csf
        End If

    End Sub

    Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
        _section = ComboBox1.SelectedValue
    End Sub

    'Private Sub FillBy3ToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy3ToolStripButton.Click
    '    Try
    '        Me.M_SectionTableAdapter.FillBy3(Me.ECollegeDataSet.M_Section)
    '    Catch ex As System.Exception
    '        System.Windows.Forms.MessageBox.Show(ex.Message)
    '    End Try

    'End Sub
End Class
